﻿using Inv_4Service.dtos;
using NHibernateEntities.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace Inv_4Service
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "HomeService" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select HomeService.svc or HomeService.svc.cs at the Solution Explorer and start debugging.
    public class HomeService : IHomeService
    {
        public string Hello()
        {
            return "Hello World!!";
        }

        public NewsDto[] News()
        {
            var result = new List<NewsDto>();
            IList<Article> list = null;
            var session = NHibernateFactory.NHibernateHelper.OpenSession();
            using (session)
            {
                list = session.CreateCriteria<Article>().List<Article>();
            }
            foreach (var item in list)
            {
                var news = new NewsDto
                {
                    Id = item.Id,
                    PostedDate = item.PostedDate,
                    Short = item.Short,
                   // Title = item.Title
                };
                result.Add(news);
            }

            return result.ToArray();
        }
    }
}
